#ifndef __AUDIO_H__
#define __AUDIO_H__

#include "libmad_driver.h"
#include <array>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#define AUDIO_CACHE_NUM 3    // 音频缓存数量

// 音频优先级定义
typedef enum {
    AUDIO_PRIORITY_NONE = 0,
    AUDIO_PRIORITY_CLICK = 1,
    AUDIO_PRIORITY_INIT,
    AUDIO_PRIORITY_MUSIC,
    AUDIO_PRIORITY_NOTIFY,
} AUDIO_PRIORITY_t;

// 音频类型定义
typedef enum {
    AUDIO_TYPE_WAV = 0,
    AUDIO_TYPE_MP3,
} AUDIO_TYPE_t;

// 单个音频节点结构体
struct AudioNode {
    AUDIO_TYPE_t type;        // 音频类型
    std::string file_path;    // 文件路径
};

using PlayEndCallback = std::function<void()>;

// 系统音频节点结构体
struct SysAudioNode {
    AUDIO_PRIORITY_t priority = AUDIO_PRIORITY_NONE;    // 默认优先级
    std::vector<AudioNode> audio_nodes;                 // 自动管理数组
    int num_nodes = 0;                                  // 音频节点数量
    PlayEndCallback play_end_callback = nullptr;        // 可选回调
};

class Audio {
public:
    static Audio& getInstance() {
        static Audio instance;
        return instance;
    }
    // 删除拷贝构造函数和赋值运算符
    Audio(const Audio&) = delete;
    Audio& operator=(const Audio&) = delete;

    void AddNode(SysAudioNode& node);
    void AddMusicListNode(const std::vector<AudioNode>& nodes, AUDIO_PRIORITY_t priority, PlayEndCallback callback);
    void AddMusicListNode(std::initializer_list<AudioNode> nodes, AUDIO_PRIORITY_t priority, PlayEndCallback callback);
    
    struct Impl;

private:
    Audio();
    ~Audio();

    std::unique_ptr<Impl> impl_;
};

#endif    // !__AUDIO_H__
